package cc.lzmsh.controller;

import cc.lzmsh.domain.entity.User;
import cc.lzmsh.domain.result.Result;
import cc.lzmsh.enums.AppHttpCodeEnum;
import cc.lzmsh.exception.SystemException;
import cc.lzmsh.service.BlogLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author:   msh
 * Date:     2024/9/18 下午2:30
 * Description:
 */

@RestController
public class BlogLoginController {
    @Autowired
    private BlogLoginService blogLoginService;

    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        // 提示用户要传入用户名
        if (user.getUserName() == null || user.getUserName().isEmpty()) {
            throw new SystemException(AppHttpCodeEnum.NICKNAME_NOT_NULL);
        }
        return blogLoginService.login(user);
    }

    @PostMapping("/logout")
    public Result logout(){
        return blogLoginService.logout();
    }
}
